package com.liang.manage.auth.facade.channel;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author maliangnansheng
 * @date 2022/6/9 18:24
 */
@Slf4j
@Component
public class RocketMqMessageChannel {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Value("${rocketmq.user.topic}")
    private String topic;

    public void send(String message) {
        SendResult sendResult = rocketMQTemplate.syncSend(topic, message);
        if (SendStatus.SEND_OK.equals(sendResult.getSendStatus())) {
            log.info("推送消息成功 > msgId: {} > topic: {} > message: {}", sendResult.getMsgId(), topic, message);
        } else {
            log.error("推送消息失败 > topic: {} > message: {}", topic, message);
        }
    }

}